(function(cdt) {
	cdt.jQ.fn.colorRotator = function(options) {
		var $colorRotatorPage = this, _o = {}, lastColorArrayIndex = null, _content = {}
		
		_o = cdt.jQ.extend({
			//mode:'random',
			mode:'sequential',
			sourceSelector:'.rotatedColor',
			colorArray:['color-1','color-2','color-3','color-4','color-5','color-6'],
			contentSpecific:true
		},options)
		
		function _initialize(){
			cdt.util.log('colorRotator._initialize','info')
			
			$colorRotatorPage.find(_o.sourceSelector).each(function(i,j){
				var _myColorArrayIndex = null
				var _myElement = cdt.jQ(j)
				
				if(_o.contentSpecific){
					if(_content[_myElement.text()] || _content[_myElement.text()] == 0){
						_myElement.addClass(_o.colorArray[_content[_myElement.text()]])
						return true
					}
				}
				
				if(_o.mode == 'sequential'){
					if(lastColorArrayIndex == null){
						_myColorArrayIndex = 0
					} else if(lastColorArrayIndex + 1 < _o.colorArray.length){
						_myColorArrayIndex = lastColorArrayIndex + 1
					} else {
						_myColorArrayIndex = 0
					}
				} else if(_o.mode == 'random') {
					_myColorArrayIndex = cdt.util.rand(0,_o.colorArray.length-1)
				}
				
				_myElement.addClass(_o.colorArray[_myColorArrayIndex])
				lastColorArrayIndex = _myColorArrayIndex
				
				if(_o.contentSpecific){
					_content[_myElement.text()] = _myColorArrayIndex
				}
			})
			
			return $colorRotatorPage
		}
		
		return _initialize()
	}
})(cdt);